﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace DbSharp.Framework.Common
{
    static class DateTimeParser
    {
        public static DateTime ParseExactUtc(string s, string format)
        {
            //http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
            //http://blogs.msdn.com/bclteam/archive/2004/05/21/136918.aspx
            
            DateTimeStyles styles = DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal | DateTimeStyles.NoCurrentDateDefault;
            return DateTime.ParseExact(s, format, CultureInfo.InvariantCulture, styles);
        }


        public static DateTimeOffset ParseExactUtcOffset(string s, string format)
        {
            //http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
            //http://blogs.msdn.com/bclteam/archive/2004/05/21/136918.aspx

            DateTimeStyles styles = DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal | DateTimeStyles.NoCurrentDateDefault;
            return DateTimeOffset.ParseExact(s, format, CultureInfo.InvariantCulture, styles);
        }

        public static DateTime ParseUtc(string s)
        {
            DateTimeStyles styles;
            //styles = DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal | DateTimeStyles.NoCurrentDateDefault;
            styles = DateTimeStyles.AssumeUniversal | DateTimeStyles.NoCurrentDateDefault;
            return DateTime.Parse(s, CultureInfo.InvariantCulture, styles);
        }

    }
}
